/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package visual;

import java.awt.Color;
import java.awt.Graphics;
import java.io.InputStream;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import javax.swing.JPanel;

/**
 *
 * @author Michał
 */
public class Chart extends JPanel {
    private double Ymax;
    private int numOfSamples; // liczba wyników wyświetlanych na wykresie
    private LinkedList<Double> values;
    
    public Chart() {
        super();
        values = new LinkedList<Double>();
        Ymax=2;
        numOfSamples=50;
    }
    
    
    public void addRecentResult(double value) {
        if(values.size() == numOfSamples) 
            values.removeFirst();
        if(value>Ymax) value=Ymax; 
        values.addLast(value);
        repaint();
    }
    
    public void rescale(double newYMax) {
        Ymax = newYMax;
    }
    
    public void resize(int newNumOfSamples) {
        numOfSamples = newNumOfSamples;
    }

    
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        ListIterator<Double> it = values.listIterator();
        int i=0;
        while(it.hasNext()) {
           // System.out.println(i*(getSize().width/numOfSamples));
            g.drawOval(i*(getSize().width/numOfSamples), 
                       getSize().height-(int)(getSize().height*(it.next()/Ymax)), 2, 2);
            i++;
        }
    }
}
